//
//  EquipmentDetailViewController.m
//  LOL_JewelBox
//
//  Created by dllo on 15/4/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "EquipmentDetailViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+WebCache.h"
#import "DetailModel.h"
#import "ToolsView.h"
@interface EquipmentDetailViewController ()

@property(nonatomic, retain)ToolsView *toolsView;
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)NSMutableDictionary *equipmentDic;

@property(nonatomic, retain)UILabel *detailName;       // 名称
@property(nonatomic, retain)UILabel *detailAllPrice;   // 总价
@property(nonatomic, retain)UILabel *detailSellPrice;  // 卖价
@property(nonatomic, retain)UILabel *detailDescription;// 属性


@end


@implementation EquipmentDetailViewController

- (void)dealloc
{
    
    [_toolsView release];
    [_scrollView release];
    [_equipmentDic release];
    [_detailName release];
    [_detailAllPrice release];
    [_detailSellPrice release];
    [_detailDescription release];
    [super dealloc];
    
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.equipmentDic = [NSMutableDictionary dictionary];
        self.title = @"装备详情";
    }
    return self;
}


- (void)equipmentData
{
    AFHTTPRequestOperationManager *managerEquipment = [AFHTTPRequestOperationManager manager];
    
    NSString *equipmentstr = [NSString stringWithFormat:@"http://lolbox.duowan.com/phone/apiItemDetail.php?id=%@&v=86&OSType=iOS8.3", self.equipmentid];
    
    [managerEquipment GET:equipmentstr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSMutableDictionary *dic = responseObject;
      
        [self.equipmentDic setValuesForKeysWithDictionary:dic];
        
        [self createView];
        
        NSString *name = [NSString stringWithFormat:@" 名称: %@", [dic objectForKey:@"name"]];
        self.detailName.text = name;
        [self.toolsView addSubview:self.detailName];
        
        NSString *allPrice = [NSString stringWithFormat:@" 总价: %@金币", [dic objectForKey:@"allPrice"]];
        self.detailAllPrice.text = allPrice;
        [self.toolsView addSubview:self.detailAllPrice];
        
        NSString *sellPrice = [NSString stringWithFormat:@" 卖价: %@金币", [dic objectForKey:@"sellPrice"]];
        self.detailSellPrice.text = sellPrice;
        [self.toolsView addSubview:self.detailSellPrice];
        
        NSString *description = [NSString stringWithFormat:@"%@", [dic objectForKey:@"description"]];
        self.detailDescription.text = description;
        [self.scrollView addSubview:self.detailDescription];
    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 解析数据开始
    [self equipmentData];
    // 铺设自定义View
    self.toolsView = [[ToolsView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
    [self.view addSubview:self.toolsView];
    self.toolsView.backgroundColor = [UIColor colorWithRed:218 / 255.0 green:218 / 255.0 blue:218 / 255.0 alpha:1];
    [_toolsView release];
    
    
    // 图片位置
    UIImageView *detailPng = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
    NSString *strPng = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png", self.equipmentid];
    NSURL *url = [NSURL URLWithString:strPng];
    [detailPng sd_setImageWithURL:url];
    [self.toolsView addSubview:detailPng];
    [detailPng release];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(31, 200, VIEWWIDTH - 62, VIEWHEIGHT / 3.368)];
    self.scrollView.contentSize = CGSizeMake(VIEWWIDTH - 62, 300);
    [self.toolsView addSubview:self.scrollView];
    self.scrollView.layer.borderWidth = 1;
    self.scrollView.layer.cornerRadius = 10;
    self.scrollView.backgroundColor = [UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1];
    [_scrollView release];


}

// 详情
- (void)createView
{
    
    // 名称
    self.detailName = [[UILabel alloc] initWithFrame:CGRectMake(130, 20, 200, 30)];
    [_detailName release];
    
    // 总价
    self.detailAllPrice = [[UILabel alloc] initWithFrame:CGRectMake(130, 55, 200, 30)];
    [_detailAllPrice release];
    
    // 卖价
    self.detailSellPrice = [[UILabel alloc] initWithFrame:CGRectMake(130, 90, 200, 30)];
    [_detailSellPrice release];
    
    // 属性
    UILabel *textdescription = [[UILabel alloc] initWithFrame:CGRectMake(30, 170, 100, 30)];
    textdescription.text = @"属性:";
    textdescription.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    [self.toolsView addSubview:textdescription];
    [textdescription release];
    
    self.detailDescription = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , VIEWWIDTH - 62, 240)];
    self.detailDescription.numberOfLines = 0;
    self.detailDescription.lineBreakMode = NSLineBreakByCharWrapping;
    [self.scrollView addSubview:self.detailDescription];
    [_detailDescription release];
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
